/**
 * 
 */
package ru.cargobroker.workbench.registry.util;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import ru.cargobroker.workbench.registry.domain.PerspectiveDescriptor;
import ru.cargobroker.workbench.registry.services.PerspectiveRegistry;

/**
 * @author M.Frendiy
 * @since 0.1
 *
 */
@Component
public class SimplePerspectiveDiscover {
	private static final Logger LOG = Logger.getLogger(SimplePerspectiveDiscover.class);
	
	private List<PerspectiveDescriptor> perspectives;
	private PerspectiveRegistry registry;
	
	
	public void setPerspectives(List<PerspectiveDescriptor> persDesc) {
		Assert.notEmpty(persDesc);
		
		this.perspectives = persDesc;
	}
	
	public void apply() {
		LOG.debug("Will added list of perspectives: " + StringUtils.collectionToCommaDelimitedString(perspectives));

		for (PerspectiveDescriptor desc : perspectives) {
			registry.addPerspective(desc);
		} 
	}

	public PerspectiveRegistry getRegistry() {
		return registry;
	}

	public void setRegistry(PerspectiveRegistry registry) {
		this.registry = registry;
	}

	public List<PerspectiveDescriptor> getPerspectives() {
		return perspectives;
	}
}
